package com.xt.website.controller;

import com.xt.website.po.News;
import com.xt.website.po.NewsExt;
import com.xt.website.service.NewsService;
import com.xt.website.util.MyPageInfo;
import com.xt.website.util.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/*
 * @Author 爱尚实训赵国鑫
 * @ClassName  NewsController
 * @Date 2019/8/18/13:38
 * @Description TODO:(一句话描述这个类)
 */
@RequestMapping("/news")
@RestController
public class NewsController {
    @Resource
    private NewsService newsService;


    /**
     * 根据一级类目查询全部新闻
     *
     * @param pageNow 当前页码
     * @param cid     一级类目id
     * @return MyPageInfo<News>
     */
    @RequestMapping("/findNewsByCid")
    public String findNewsByCid(Integer pageNow, Integer cid,String callback,Integer pageSize) {

        MyPageInfo<News> myPageInfo = newsService.findNewsByCid(pageNow, cid,pageSize);

        return Result.result(myPageInfo,callback);
    }

    /**
     * 根据二级类目查询全部新闻
     *
     * @param pageNow 当前页码
     * @param csid    二级类目id
     * @return MyPageInfo<News>
     */
    @RequestMapping("/findNewsByCsid")
    public String findNewsByCsid(Integer pageNow, Integer csid,String callback,Integer pageSize) {
        MyPageInfo<News> pageInfo = newsService.findNewsByCsid(pageNow, csid,pageSize);
        return Result.result(pageInfo,callback);
    }


    /**
     * 根据新闻id获取新闻详情
     *
     * @param news 新闻id,二级类目id
     * @return
     */
    @RequestMapping("/newsDetail")
    public String newsDetail(News news,String callback) {
        NewsExt newsExt = newsService.findNewsExt(news);
        return Result.result(newsExt,callback);
    }
}
